<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<h1>${info.title}</h1>
<p>发表于：${info.reporttime?string("yyyy-MM-dd HH:mm:ss")}</p>
<p>${info.content}</p>
<div id="rep">
    <h4>读者回应</h4>
    <#if replies??>
        <#list replies as rep>
            <div style="background: gainsboro;margin-bottom: 10px">
                <p>${rep.replytime?string("yyyy-MM-dd HH:mm:ss")}</p>
                <p>${rep.content}</p>
            </div>
        </#list>
    </#if>

</div>

<div>
    <p>发表回复：(字数在200字以内)</p>
    <form action="" method="post">
        <input type="hidden" id="newsId" value="${info.id}">
        <textarea rows="10" cols="40" id="txt"></textarea>
        <p><input type="submit" value="发表回复"><a href="/index">返回首页</a> </p>
    </form>
</div>

<script src="/js/jquery-3.5.1.js"></script>
<script type="text/javascript">
    $(function () {
        $("form").submit(function () {
           var content= $("#txt").val()
            var myDate=new Date();
            var replytime=myDate.getFullYear()+"-"+(myDate.getMonth()+1)+"-"+myDate.getDate()+" "+myDate.getHours()+":"+myDate.getMinutes()+":"+myDate.getSeconds();
            console.log(replytime);
            var infoid=$("#newsId").val();
            $.ajax({
                url:"/add",
                type:"post",
                dataType:"json",
                contentType:"application/json;charset=utf-8",
                data:JSON.stringify({
                    "content":content,
                    "replytime":replytime,
                    "infoid":infoid
                }),
                success:function (data) {
                    console.log(data)
                    if(data.code==200){
                        $("#rep").append("   <div style=\"background: gainsboro;margin-bottom: 10px\">\n" +
                            "                <p>"+replytime+"</p>\n" +
                            "                <p>"+content+"</p>\n" +
                            "            </div>")
                    }
                }

            })

            return false;
        })
    })
</script>
</body>
</html>